s = "3 8 5 1 6 3 4 6 7 0 7 8 2 7 6 8 9 5 6 5 6 1 4 0 1 0 0 9 4 8 0 9 1 2 8 5 0 2 5 3 3"
s = list(s.split(" "))

days = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
ans = set()
n = len(s)

for i in range(n):
    c = []
    if s[i] in ["0", "1"]:
        c.append(s[i])
        for j in range(i + 1, n):
            if (c[0] == "1" and 0 <= int(s[j]) <= 2) or (c[0] == "0" and 1 <= int(s[j]) <= 9):
                c.append(s[j])
                for x in range(j + 1, n):
                    if s[x] in "0123":
                        c.append(s[x])
                        for y in range(x + 1, n):
                            c.append(s[y])
                            month_str = "".join(c[:2])
                            day_str = "".join(c[2:])
                            month = int(month_str)
                            day = int(day_str)
                            if 1 <= month <= 12 and 1 <= day <= days[month]:
                                ans.add(tuple(c))
                            c.pop()
                        c.pop()
                c.pop()
        c.pop()
# print(ans)
print(len(ans))